// packageA/pages/jietu1/jietu1.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    appurl: app.apiurl,
    apiimg: app.apiimg,
    ggid:'',
    gglist:'',
    array2: [],
    index2: 0,
    jietu:'/image/3qi/jietu.jpg',
    // jietu:'/image/3qi/icon05.png',
    jietu1:''
  },
  bindPickerChange2: function(e) {
    let _this = this
    let game_dw = _this.data.game_dw
    game_dw = _this.data.duanwei[e.detail.value].id
    this.setData({
      index2: e.detail.value,
      game_dw:game_dw
    })
  },
  z_goback(){
    wx.navigateBack({
      delta: 1
    })
  },
  upload() {
    let that = this
    wx.chooseMedia({
      count: 1,
      mediaType: ['image'],
      sourceType: ['album'],
      maxDuration: 30,
      camera: 'back',
      success(res) {
        var tempFiles = res.tempFiles[0]['tempFilePath'];
        var fileSize = res.tempFiles[0]['size'];
        var MAX_SIZE = Number(that.data.peizhi.config_param39) * 1024 * 1024;
        if (fileSize > MAX_SIZE) {
          wx.showToast({
            title: '文件超过大小限制',
            icon: 'none',
          });
          // 文件超过限制，处理逻辑，比如重新选择
          return;
        } else {
          wx.uploadFile({
            url: app.apiurl + 'api/common/upload',
            filePath: tempFiles,
            name: 'file',
            formData: {},
            success(res) {
              const data = JSON.parse(res.data)
              that.setData({
                jietu:data.data.fullurl,
                jietu1:data.data.fullurl
              })
              that.upload1()
            }
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      id:options.id,
      member_name:options.member_name,
      diff_minute:options.diff_minute
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.guanggao1()
    this.gameduanwei()
    // this.z_duifang()
    this.z_idxgg()
    this.z_peizhi()
    this.z_yonghu()
  },
  z_yonghu() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/member/myInfo',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        if (res.data.code == '1001') {
          let tmp_khgjs_pm = '0';
          if (res.data.data.khgjs_pm > 10) {
            tmp_khgjs_pm = '10+'
          }else{
            tmp_khgjs_pm = res.data.data.khgjs_pm
          }
          _this.setData({
            login: true,
            yonghu: res.data.data,
            khgjs_pm_index: tmp_khgjs_pm
          })
        }
      }
    })
  },
  z_peizhi() {
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/configBase',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          peizhi:res.data.data
        })
      }
    })
  },
  z_idxgg(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/home/index',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          login:true,
          idx_gg:res.data.data,
          // time1:res.data.data.activity_info.diff_time
        })
        // _this.z_time()
      }
    })
  },
  guanggao1(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/advertPage',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
         _this.setData({
           ggid:res.data.data[0].id
         })
         _this.guanggao2()
      }
    })
  },
  guanggao2(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/advert?page_id=2',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
         _this.setData({
           gglist:res.data.data[0]
         })
      }
    })
  },
  z_kvlianjia(e){
    let _this = this
    let link_url = e.currentTarget.dataset.url
    let id = e.currentTarget.dataset.url
    if(link_url != undefined){
      wx.navigateTo({
        url: link_url,
      })
    }
  },
  gameduanwei(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/gameDw?game_type_id=1',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        let array2 = _this.data.array2
        for(let i=0;i<res.data.data.length;i++){
          array2.push(res.data.data[i].name)
        }
        _this.setData({
          duanwei:res.data.data,
          array2:array2,
        })
      }
    })
  },
    //对方资料
z_duifang() {
  let _this = this
  let params = {
    "token":wx.getStorageSync("user_token"),
  }
  wx.request({
    url: app.apiurl + 'api/member/otherMemberInfo?other_member_id=' + _this.data.other_member_id,
    method: 'POST',
    data: params,
    header: {
      'content-type': 'application/x-www-form-urlencoded' // 修改请求
    },
    success(res) {
      _this.setData({
        duifang:res.data.data
      })
    }
  })
},
upload1(){
  let _this = this
  let params = {
    "token":wx.getStorageSync("user_token"),
    "id":_this.data.id,
    "pic":_this.data.jietu
  }
  wx.request({
    url: app.apiurl + 'api/member_kh/up_kh_pic',
    method: 'POST',
    data: params,
    header: {
      'content-type': 'application/x-www-form-urlencoded' // 修改请求
    },
    success(res) {
      wx.showToast({
        title: res.data.msg,
        icon: 'none',
        duration: 2000
      })
    }
  })
},
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})